home *** CD-ROM | disk | FTP | other *** search
/ 1,000+ Great Games / 1_1000 Games.iso / DOSGAMES / BOGGLE.ZIP / SOURCE.ZIP / SCORE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-03  |  2.9 KB  |  100 lines

  1. /*****************************************************************************
  2. * Program:  SCORE.CPP
  3. * Purpose:  responsible for maintaining the score of the game
  4. *****************************************************************************/
  5. #include "score.hpp"
  6. #include  <stdio.h>                 
  7.  
  8. /*****************************************************************************
  9. * Function: TBogScore
  10. * Parms:    parent windows 
  11. * Purpose:  Constructor - set up the static text field for the score
  12. * Returns:  nothing
  13. *****************************************************************************/
  14. TBogScore::TBogScore(unsigned long id,
  15.                       IWindow* parent,
  16.                       IWindow* owner)
  17.          :  IStaticText(id, parent, owner),
  18.             myFont(this)
  19. {
  20.    score_value = 0;
  21.    sprintf(sScore, "%d", score_value);
  22.  
  23. //Set up the font for the text control
  24.    setAlignment(IStaticText::centerCenter);
  25.    myFont.setName("Swiss")
  26.          .setPointSize(10)
  27.          .setBold()
  28.          .setItalic();
  29.    setFont((myFont));
  30.  
  31. //Set the color
  32.    setColor(background, IColor::darkGray);
  33.  
  34. //Display the actual score
  35.    setText(sScore);
  36. }
  37.  
  38. /*****************************************************************************
  39. * Function: ~TBogScore
  40. * Parms:    none
  41. * Purpose:  Destructor
  42. * Returns:  nothing
  43. *****************************************************************************/
  44. TBogScore::~TBogScore()
  45. {
  46. }
  47.  
  48. /*****************************************************************************
  49. * Function: clearScore
  50. * Parms:    none
  51. * Purpose:  Set the score back to zero
  52. * Returns:  nothing
  53. *****************************************************************************/
  54. void TBogScore::clearScore()
  55. {
  56.    score_value = 0;
  57.  
  58. //Display the actual score
  59.    displayScore();
  60. }
  61.  
  62. /*****************************************************************************
  63. * Function: calcScore
  64. * Parms:    nLetters - number of letters in word to score
  65. * Purpose:  based on the # of letters - increment the score
  66. * Returns:  nothing
  67. *****************************************************************************/
  68. void TBogScore::calcScore(int nLetters)
  69. {
  70.    if ((nLetters > 2) && (nLetters <= 4))
  71.       score_value += 1;
  72.    else if (nLetters == 5)
  73.       score_value += 2;
  74.    else if (nLetters == 6)
  75.       score_value += 3;
  76.    else if (nLetters == 7)
  77.       score_value += 5;
  78.    else if (nLetters > 7)
  79.       score_value += 11;
  80. }
  81.  
  82. /*****************************************************************************
  83. * Function: displayScore
  84. * Parms:    none
  85. * Purpose:  show the current score on the screen
  86. * Returns:  nothing
  87. *****************************************************************************/
  88. void TBogScore::displayScore()
  89. {
  90.    char score_str[4];
  91.    static int last_score;
  92.  
  93.    sprintf(sScore, "%d", score_value);
  94.    setText(sScore);
  95.  
  96.    sprintf(score_str,"%-3.1d", score_value);
  97.  
  98.    last_score = score_value;  
  99. }
  100.